package com.xc.pay.weixin.template;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.xc.pay.WeChatPayProperties;
import com.xc.pay.weixin.enums.WxPayUrlEnum;
import com.xc.pay.weixin.modal.v3.WxAppModal;
import com.xc.pay.weixin.modal.v3.base.WxBaseModal;
import com.xc.pay.weixin.template.Base.WxPayBaseImplTemplate;
import com.xc.pay.weixin.util.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * APP模板类
 *
 * @author rongrong
 * @date 2020/11/27
 */
public class WxPayAppTemplate extends WxPayBaseImplTemplate {

  @Autowired private WeChatPayProperties weChatPayProperties;

  @Override
  public Object orderPay(WxBaseModal modal) {
    final String appid = weChatPayProperties.getApp().getAppid();
    final String mchid = weChatPayProperties.getApp().getMchid();
    final JSONObject jsonObject = JSONUtil.parseObj(modal);
    jsonObject.putOpt("appid", appid).putOpt("mchid", mchid);
    final String v3 =
        HttpUtils.postV3(WxPayUrlEnum.V3_APP_APY.url, jsonObject.toJSONString(2), httpClient);
    return v3;
  }
}
